<?php

/**
 * @Project NUKEVIET 3.0
 * @Author VINADES.,JSC (contact@vinades.vn)
 * @copyright 2009
 * @createdate 10/03/2010 10:51
 */

if ( ! defined( 'NV_IS_MOD_USER' ) )
{
    die( 'Stop!!!' );
}

function user_register ( $gfx_chk, $array_register, $siteterms, $data_questions )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head;
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#registerForm').validate({
			});
          });";
    $my_head .= "  </script>\n";
    
    $xtpl = new XTemplate( "register.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    $xtpl->assign( 'USER_REGISTER', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=register" );
    $xtpl->assign( 'NICK_MAXLENGTH', NV_UNICKMAX );
    $xtpl->assign( 'PASS_MAXLENGTH', NV_UPASSMAX );
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'DATA', $array_register );
    $xtpl->assign( 'NV_SITETERMS', $siteterms );
    foreach ( $data_questions as $array_question_i )
    {
        $xtpl->assign( 'QUESTIONVALUE', $array_question_i );
        $xtpl->parse( 'main.frquestion' );
    }
    if ( $gfx_chk )
    {
        $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
        $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
        $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
        $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
        $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
        $xtpl->assign( 'SRC_CAPTCHA', NV_BASE_SITEURL . "index.php?scaptcha=captcha" );
        $xtpl->assign( 'GFX_MAXLENGTH', NV_GFX_NUM );
        $xtpl->parse( 'main.captcha' );
    }
    
    if ( $global_config['allowuserreg'] == 2 )
    {
        $xtpl->assign( 'LOSTACTIVELINK_SRC', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=lostactivelink" );
        $xtpl->parse( 'main.lostactivelink' );
    }
    
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function openid_register ( $gfx_chk, $array_register, $siteterms, $data_questions )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head, $nv_redirect;
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#registerForm').validate({
			});
          });";
    $my_head .= "  </script>\n";
    
    $xtpl = new XTemplate( "openid_register.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    $xtpl->assign( 'USER_REGISTER', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=register&amp;openid=1" );
    $xtpl->assign( 'NICK_MAXLENGTH', NV_UNICKMAX );
    $xtpl->assign( 'PASS_MAXLENGTH', NV_UPASSMAX );
    $xtpl->assign( 'OPENID_IMG_SRC', NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/openid.gif" );
    $xtpl->assign( 'OPENID_IMG_WIDTH', 150 );
    $xtpl->assign( 'OPENID_IMG_HEIGHT', 60 );
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'DATA', $array_register );
    $xtpl->assign( 'NV_SITETERMS', $siteterms );
    
    foreach ( $data_questions as $array_question_i )
    {
        $xtpl->assign( 'QUESTIONVALUE', $array_question_i );
        $xtpl->parse( 'main.frquestion' );
    }
    
    if ( $gfx_chk )
    {
        $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
        $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
        $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
        $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
        $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
        $xtpl->assign( 'SRC_CAPTCHA', NV_BASE_SITEURL . "?scaptcha=captcha" );
        $xtpl->assign( 'GFX_MAXLENGTH', NV_GFX_NUM );
        $xtpl->parse( 'main.captcha' );
    }
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function user_login ( $gfx_chk, $array_login )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head, $openid_servers;
    
    $xtpl = new XTemplate( "login.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/users" );
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#loginForm').validate();
          });";
    $my_head .= "  </script>\n";
    
    $xtpl->assign( 'USER_LOGIN', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login" );
    $xtpl->assign( 'USER_REGISTER', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=register" );
    $xtpl->assign( 'USER_LOSTPASS', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=lostpass" );
    $xtpl->assign( 'NICK_MAXLENGTH', NV_UNICKMAX );
    $xtpl->assign( 'PASS_MAXLENGTH', NV_UPASSMAX );
    
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'DATA', $array_login );
    
    if ( $gfx_chk )
    {
        $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
        $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
        $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
        $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
        $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
        $xtpl->assign( 'SRC_CAPTCHA', NV_BASE_SITEURL . "?scaptcha=captcha" );
        $xtpl->assign( 'GFX_MAXLENGTH', NV_GFX_NUM );
        $xtpl->parse( 'main.captcha' );
    }
    
    if ( defined( 'NV_OPENID_ALLOWED' ) )
    {
        $xtpl->assign( 'OPENID_IMG_SRC', NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/openid.gif" );
        $xtpl->assign( 'OPENID_IMG_WIDTH', 150 );
        $xtpl->assign( 'OPENID_IMG_HEIGHT', 60 );
        
        $assigns = array();
        foreach ( $openid_servers as $server => $value )
        {
            $assigns['href'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login&amp;server=" . $server;
            $assigns['title'] = ucfirst( $server );
            $assigns['img_src'] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/" . $server . ".gif";
            $assigns['img_width'] = $assigns['img_height'] = 24;
            
            $xtpl->assign( 'OPENID', $assigns );
            $xtpl->parse( 'main.openid.server' );
        }
        
        $xtpl->parse( 'main.openid' );
    }
    
    $xtpl->parse( 'main' );
    
    return $xtpl->text( 'main' );
}

function user_openid_login ( $gfx_chk, $array_login, $attribs )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head, $openid_servers;
    
    $xtpl = new XTemplate( "openid_login.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/users" );
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#loginForm').validate();
          });";
    $my_head .= "  </script>\n";
    
    $xtpl->assign( 'USER_LOGIN', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login&amp;server=" . $attribs['server'] . "&amp;result=1&amp;option=3" );
    $xtpl->assign( 'USER_REGISTER', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=register" );
    $xtpl->assign( 'USER_LOSTPASS', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=lostpass" );
    $xtpl->assign( 'NICK_MAXLENGTH', NV_UNICKMAX );
    $xtpl->assign( 'PASS_MAXLENGTH', NV_UPASSMAX );
    $xtpl->assign( 'OPENID_IMG_SRC', NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/openid.gif" );
    $xtpl->assign( 'OPENID_IMG_WIDTH', 150 );
    $xtpl->assign( 'OPENID_IMG_HEIGHT', 60 );
    
    $assigns = array();
    foreach ( $openid_servers as $server => $value )
    {
        $assigns['href'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login&amp;server=" . $server;
        $assigns['title'] = ucfirst( $server );
        $assigns['img_src'] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/" . $server . ".gif";
        $assigns['img_width'] = $assigns['img_height'] = 24;
        
        $xtpl->assign( 'OPENID', $assigns );
        $xtpl->parse( 'main.server' );
    }
    
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'DATA', $array_login );
    
    if ( $gfx_chk )
    {
        $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
        $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
        $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
        $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
        $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
        $xtpl->assign( 'SRC_CAPTCHA', NV_BASE_SITEURL . "?scaptcha=captcha" );
        $xtpl->assign( 'GFX_MAXLENGTH', NV_GFX_NUM );
        $xtpl->parse( 'main.captcha' );
    }
    
    $xtpl->parse( 'main' );
    
    return $xtpl->text( 'main' );
}

function user_openid_login2 ( $attribs, $array_user_login )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head, $openid_servers, $nv_redirect;
    
    $xtpl = new XTemplate( "openid_login2.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/users" );
    
    $xtpl->assign( 'USER_REGISTER', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=register&amp;nv_redirect=" . $nv_redirect );
    $xtpl->assign( 'USER_LOSTPASS', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=lostpass&amp;nv_redirect=" . $nv_redirect );
    $xtpl->assign( 'OPENID_IMG_SRC', NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/openid.gif" );
    $xtpl->assign( 'OPENID_IMG_WIDTH', 150 );
    $xtpl->assign( 'OPENID_IMG_HEIGHT', 60 );
    
    foreach ( $array_user_login as $value )
    {
        $xtpl->assign( 'USER_LOGIN', $value );
        $xtpl->parse( 'main.login_note' );
    }
    
    $assigns = array();
    foreach ( $openid_servers as $server => $value )
    {
        $assigns['href'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login&amp;server=" . $server . "&amp;nv_redirect=" . $nv_redirect;
        $assigns['title'] = ucfirst( $server );
        $assigns['img_src'] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/" . $server . ".gif";
        $assigns['img_width'] = $assigns['img_height'] = 24;
        
        $xtpl->assign( 'OPENID', $assigns );
        $xtpl->parse( 'main.server' );
    }
    
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->parse( 'main' );
    
    return $xtpl->text( 'main' );
}

function user_lostpass ( $data, $question )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head;
    
    $xtpl = new XTemplate( "lostpass.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#lostpassForm').validate();
          });";
    $my_head .= "  </script>\n";
    
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'DATA', $data );
    
    if ( $data['step'] == 2 )
    {
        $xtpl->assign( 'FORM2_ACTION', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=lostpass" );
        $xtpl->assign( 'QUESTION', $question );
        $xtpl->parse( 'main.step2' );
    }
    else
    {
        $xtpl->assign( 'FORM1_ACTION', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=lostpass" );
        $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
        $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
        $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
        $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
        $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
        $xtpl->assign( 'SRC_CAPTCHA', NV_BASE_SITEURL . "?scaptcha=captcha" );
        $xtpl->assign( 'GFX_MAXLENGTH', NV_GFX_NUM );
        $xtpl->parse( 'main.step1' );
    }
    
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function user_lostactivelink ( $data, $question )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head;
    
    $xtpl = new XTemplate( "lostactivelink.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#lostpassForm').validate();
          });";
    $my_head .= "  </script>\n";
    
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'DATA', $data );
    
    if ( $data['step'] == 2 )
    {
        $xtpl->assign( 'FORM2_ACTION', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=lostactivelink" );
        $xtpl->assign( 'QUESTION', $question );
        $xtpl->parse( 'main.step2' );
    }
    else
    {
        $xtpl->assign( 'FORM1_ACTION', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=lostactivelink" );
        $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
        $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
        $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
        $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
        $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
        $xtpl->assign( 'SRC_CAPTCHA', NV_BASE_SITEURL . "?scaptcha=captcha" );
        $xtpl->assign( 'GFX_MAXLENGTH', NV_GFX_NUM );
        $xtpl->parse( 'main.step1' );
    }
    
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function user_changepass ( $array_data = array() )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head;
    
    $groups_list = nv_groups_list_pub();
    
    $xtpl = new XTemplate( "changepass.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#changePassForm').validate();
          });";
    $my_head .= "  </script>\n";
    
    $xtpl->assign( 'USER_CHANGEPASS', "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=changepass" );
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'DATA', $array_data );
    $xtpl->assign( 'PASS_MAXLENGTH', NV_UPASSMAX );
    
    $xtpl->assign( 'URL_HREF', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" );
    
    if ( defined( 'NV_OPENID_ALLOWED' ) )
    {
        $xtpl->parse( 'main.allowopenid' );
    }
    
    if ( ! defined( 'NV_IS_ADMIN' ) )
    {
        $xtpl->parse( 'main.logout' );
    }
    if ( ! empty( $groups_list )&& $global_config['allowuserpublic']==1 )
    {
        $xtpl->parse( 'main.regroups' );
    }
    
    if ( ! $array_data['pass_empty'] )
    {
        $xtpl->parse( 'main.passEmpty' );
    }
    
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function user_changequestion ( $array_data )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head;
    
    $groups_list = nv_groups_list_pub();
    
    $xtpl = new XTemplate( "changequestion.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#changeQuestionForm').validate();
          });";
    $my_head .= "  </script>\n";
    
    $xtpl->assign( 'LANG', $lang_module );
    
    $xtpl->assign( 'URL_HREF', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" );
    
    if ( defined( 'NV_OPENID_ALLOWED' ) )
    {
        $xtpl->parse( 'main.allowopenid' );
    }
    if ( ! empty( $groups_list )&& $global_config['allowuserpublic']==1 )
    {
        $xtpl->parse( 'main.regroups' );
    }
    if ( ! defined( 'NV_IS_ADMIN' ) )
    {
        $xtpl->parse( 'main.logout' );
    }
    
    $xtpl->assign( 'DATA', $array_data );
    
    if ( $array_data['step'] == 2 )
    {
        $xtpl->assign( 'FORM2_ACTION', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=editinfo&amp;changequestion=1" );
        foreach ( $array_data['questions'] as $key => $question )
        {
            $xtpl->assign( 'QUESTIONVALUE', $key );
            $xtpl->assign( 'QUESTIONTITLE', $question );
            $xtpl->parse( 'main.step2.frquestion' );
        }
        $xtpl->parse( 'main.step2' );
    }
    else
    {
        $xtpl->assign( 'FORM1_ACTION', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=editinfo&amp;changequestion=1" );
        $xtpl->assign( 'PASS_MAXLENGTH', NV_UPASSMAX );
        $xtpl->parse( 'main.step1' );
    }
    
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function user_info ( $data )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head;
    
    $groups_list = nv_groups_list_pub();
    
    $xtpl = new XTemplate( "info.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/popcalendar/popcalendar.js\"></script>\n";
    
    $xtpl->assign( 'EDITINFO_FORM', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=editinfo" );
    $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
    $xtpl->assign( 'LANG', $lang_module );
    
    $xtpl->assign( 'URL_HREF', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" );
    
    if ( defined( 'NV_OPENID_ALLOWED' ) )
    {
        $xtpl->parse( 'main.allowopenid' );
    }
    if (  ! empty( $groups_list )&& $global_config['allowuserpublic']==1 )
    {
        $xtpl->parse( 'main.regroups' );
    }
    if ( ! defined( 'NV_IS_ADMIN' ) )
    {
        $xtpl->parse( 'main.logout' );
    }
    
    $xtpl->assign( 'DATA', $data );
    
    if ( $data['allowloginchange'] )
    {
        $xtpl->assign( 'NICK_MAXLENGTH', NV_UNICKMAX );
        $xtpl->parse( 'main.username_change' );
    }
    else
    {
        $xtpl->parse( 'main.username_no_change' );
    }
    
    if ( $data['allowmailchange'] )
    {
        $xtpl->parse( 'main.email_change' );
    }
    else
    {
        $xtpl->parse( 'main.email_no_change' );
    }
    
    foreach ( $data['gender_array'] as $gender )
    {
        $xtpl->assign( 'GENDER', $gender );
        $xtpl->parse( 'main.gender_option' );
    }
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function user_welcome ( )
{
    global $module_info, $module_file, $global_config, $lang_global, $lang_module, $module_name, $my_head, $user_info, $lang_global;
    
    $xtpl = new XTemplate( "userinfo.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    
    $xtpl->assign( 'LANG', $lang_module );
    
    $xtpl->assign( 'URL_HREF', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" );
    
    $groups_list = nv_groups_list_pub();
    
    if ( defined( 'NV_OPENID_ALLOWED' ) )
    {
        $xtpl->parse( 'main.allowopenid' );
    }
   
    if ( ! defined( 'NV_IS_ADMIN' ) )
    {
        $xtpl->parse( 'main.logout' );
    }
   if (  (! empty( $groups_list )) && ($global_config['allowuserpublic']==1) )
    {
        $xtpl->parse( 'main.regroups' );
    }
    
    if ( ! empty( $user_info['photo'] ) and file_exists( NV_ROOTDIR . "/" . $user_info['photo'] ) )
    {
        $xtpl->assign( 'SRC_IMG', NV_BASE_SITEURL . $user_info['photo'] );
    }
    else
    {
        $xtpl->assign( 'SRC_IMG', NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/no_avatar.jpg" );
    }
    
    $user_info['gender'] = ( $user_info['gender'] == "M" ) ? $lang_module['male'] : ( $user_info['gender'] == 'F' ? $lang_module['female'] : $lang_module['na'] );
    $user_info['birthday'] = empty( $user_info['birthday'] ) ? $lang_module['na'] : nv_date( 'd/m/Y', $user_info['birthday'] );
    $user_info['regdate'] = nv_date( 'd/m/Y', $user_info['regdate'] );
    $user_info['website'] = empty( $user_info['website'] ) ? $lang_module['na'] : "<a href=\"" . $user_info['website'] . "\" target=\"_blank\">" . $user_info['website'] . "</a>";
    $user_info['location'] = empty( $user_info['location'] ) ? $lang_module['na'] : $user_info['location'];
    $user_info['yim'] = empty( $user_info['yim'] ) ? $lang_module['na'] : $user_info['yim'];
    $user_info['telephone'] = empty( $user_info['telephone'] ) ? $lang_module['na'] : $user_info['telephone'];
    $user_info['fax'] = empty( $user_info['fax'] ) ? $lang_module['na'] : $user_info['fax'];
    $user_info['mobile'] = empty( $user_info['mobile'] ) ? $lang_module['na'] : $user_info['mobile'];
    $user_info['view_mail'] = empty( $user_info['view_mail'] ) ? $lang_module['no'] : $lang_module['yes'];
    $user_info['last_login'] = empty( $user_info['last_login'] ) ? '' : nv_date( 'l, d/m/Y H:i', $user_info['last_login'] );
    $user_info['current_login'] = nv_date( 'l, d/m/Y H:i', $user_info['current_login'] );
    $user_info['st_login'] = ! empty( $user_info['st_login'] ) ? $lang_module['yes'] : $lang_module['no'];
    
    if ( isset( $user_info['current_mode'] ) and $user_info['current_mode'] == 3 )
    {
        $user_info['current_mode'] = $lang_module['admin_login'];
    }
    elseif ( isset( $user_info['current_mode'] ) and $user_info['current_mode'] == 2 )
    {
        $user_info['current_mode'] = $lang_module['openid_login'] . ': ' . $user_info['openid_server'] . ' (' . $user_info['openid_email'] . ')';
    }
    else
    {
        $user_info['current_mode'] = $lang_module['st_login'];
    }
    
    $user_info['change_name_info'] = sprintf( $lang_module['change_name_info'], NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=editinfo" );
    $user_info['pass_empty_note'] = sprintf( $lang_module['pass_empty_note'], NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=changepass" );
    $user_info['question_empty_note'] = sprintf( $lang_module['question_empty_note'], NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=editinfo&amp;changequestion" );
    
    $xtpl->assign( 'USER', $user_info );
    
    if ( ! $global_config['allowloginchange'] and ! empty( $user_info['current_openid'] ) and empty( $user_info['last_login'] ) and empty( $user_info['last_agent'] ) and empty( $user_info['last_ip'] ) and empty( $user_info['last_openid'] ) )
    {
        $xtpl->parse( 'main.change_login_note' );
    }
    
    if ( $user_info['st_login'] == $lang_module['no'] )
    {
        $xtpl->parse( 'main.pass_empty_note' );
    }
    
    if ( empty( $user_info['valid_question'] ) )
    {
        $xtpl->parse( 'main.question_empty_note' );
    }
    
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function user_info_exit ( $info )
{
    global $module_info, $module_file;
    
    $xtpl = new XTemplate( "info_exit.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    $xtpl->assign( 'INFO', $info );
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function openid_account_confirm ( $gfx_chk, $attribs )
{
    global $my_head, $lang_global, $lang_module, $module_info, $module_file, $module_name, $openid_servers, $nv_redirect;
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#loginForm').validate();
          });";
    $my_head .= "  </script>\n";
    
    $xtpl = new XTemplate( "confirm.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'OPENID_LOGIN', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login&amp;server=" . $attribs['server'] . "&amp;result=1" );
    $xtpl->assign( 'OPENID_IMG_SRC', NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/openid.gif" );
    $xtpl->assign( 'OPENID_IMG_WIDTH', 150 );
    $xtpl->assign( 'OPENID_IMG_HEIGHT', 60 );
    if ( $gfx_chk )
    {
        $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
        $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
        $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
        $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
        $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
        $xtpl->assign( 'SRC_CAPTCHA', NV_BASE_SITEURL . "?scaptcha=captcha" );
        $xtpl->parse( 'main.captcha' );
    }
    
    $xtpl->assign( 'USER_LOGIN', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login&amp;nv_redirect=" . $nv_redirect );
    $xtpl->assign( 'USER_REGISTER', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=register&amp;nv_redirect=" . $nv_redirect );
    
    $assigns = array();
    foreach ( $openid_servers as $server => $value )
    {
        $assigns['href'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login&amp;server=" . $server;
        $assigns['title'] = ucfirst( $server );
        $assigns['img_src'] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/" . $server . ".gif";
        $assigns['img_width'] = $assigns['img_height'] = 24;
        
        $xtpl->assign( 'OPENID', $assigns );
        $xtpl->parse( 'main.server' );
    }
    
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function openid_active_confirm ( $gfx_chk, $attribs )
{
    global $my_head, $lang_global, $lang_module, $module_info, $module_file, $module_name, $openid_servers;
    
    $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.validate.js\"></script>\n";
    $my_head .= "<script type=\"text/javascript\">\n";
    $my_head .= "$(document).ready(function(){
            $('#loginForm').validate();
          });";
    $my_head .= "  </script>\n";
    
    $xtpl = new XTemplate( "active_confirm.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'OPENID_LOGIN', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login&amp;server=" . $attribs['server'] . "&amp;result=1" );
    $xtpl->assign( 'OPENID_IMG_SRC', NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/openid.gif" );
    $xtpl->assign( 'OPENID_IMG_WIDTH', 150 );
    $xtpl->assign( 'OPENID_IMG_HEIGHT', 60 );
    if ( $gfx_chk )
    {
        $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
        $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
        $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
        $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
        $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
        $xtpl->assign( 'SRC_CAPTCHA', NV_BASE_SITEURL . "?scaptcha=captcha" );
        $xtpl->parse( 'main.captcha' );
    }
    $xtpl->assign( 'USER_LOGIN', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login" );
    $xtpl->assign( 'USER_REGISTER', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=register" );
    
    $assigns = array();
    foreach ( $openid_servers as $server => $value )
    {
        $assigns['href'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=login&amp;server=" . $server;
        $assigns['title'] = ucfirst( $server );
        $assigns['img_src'] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/" . $server . ".gif";
        $assigns['img_width'] = $assigns['img_height'] = 24;
        
        $xtpl->assign( 'OPENID', $assigns );
        $xtpl->parse( 'main.server' );
    }
    
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function user_openid_administrator ( $data )
{
    global $my_head, $lang_global, $lang_module, $module_info, $module_file, $module_name, $global_config, $openid_servers;
    
    $groups_list = nv_groups_list_pub();
    
    $xtpl = new XTemplate( "openid_administrator.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    $xtpl->assign( 'LANG', $lang_module );
    $xtpl->assign( 'OPENID_IMG_SRC', NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/openid.gif" );
    $xtpl->assign( 'OPENID_IMG_WIDTH', 150 );
    $xtpl->assign( 'OPENID_IMG_HEIGHT', 60 );
    
    $xtpl->assign( 'URL_HREF', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" );
    
    if ( defined( 'NV_IS_USER_FORUM' ) )
    {
        $xtpl->parse( 'main.allowopenid' );
    }
    if ( ! empty( $groups_list )&& $global_config['allowuserpublic']==1 )
    {
        $xtpl->parse( 'main.regroups' );
    }
    if ( ! defined( 'NV_IS_ADMIN' ) )
    {
        $xtpl->parse( 'main.logout' );
    }
    
    $xtpl->assign( 'DATA', $data );
    
    if ( ! empty( $data['openid_list'] ) )
    {
        $xtpl->assign( 'FORM_ACTION', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=openid&amp;del=1" );
        
        foreach ( $data['openid_list'] as $key => $openid_list )
        {
            if ( $key % 2 == 0 )
            {
                $xtpl->assign( 'OPENID_CLASS', " gray" );
            }
            else
            {
                $xtpl->assign( 'OPENID_CLASS', "" );
            }
            $xtpl->assign( 'OPENID_LIST', $openid_list );
            $xtpl->parse( 'main.openid_empty.openid_list' );
        }
        $xtpl->parse( 'main.openid_empty' );
    }
    
    $assigns = array();
    foreach ( $openid_servers as $server => $value )
    {
        $assigns['href'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=openid&amp;server=" . $server;
        $assigns['title'] = ucfirst( $server );
        $assigns['img_src'] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/" . $server . ".gif";
        $assigns['img_width'] = $assigns['img_height'] = 24;
        
        $xtpl->assign( 'OPENID', $assigns );
        $xtpl->parse( 'main.server' );
    }
    
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

function nv_regroup_theme( $groups )
{
	global $module_info, $module_file, $module_name, $lang_module;
    $xtpl = new XTemplate( "re_groups.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
    $xtpl->assign( 'URL_HREF', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" );
    $xtpl->assign( 'LANG', $lang_module );
	
    if ( defined( 'NV_OPENID_ALLOWED' ) )
    {
        $xtpl->parse( 'main.allowopenid' );
    }

	foreach ( $groups as $group )
	{
		$xtpl->assign( 'GROUP', $group );
		$xtpl->parse( 'main.list' );
	}

    if ( ! defined( 'NV_IS_ADMIN' ) ) $xtpl->parse( 'main.logout' );
	
    $xtpl->parse( 'main' );
    return $xtpl->text( 'main' );
}

?>